const Favorite = require('../dao/favorite');
const { OK, ERR } = require('../util/util');
const Formats = require('../util/formats');

module.exports = {
    /**
     * 新建
     */
    add: function(req, res, next) {
        console.log("request params: ", "uid=", req.body.uid, "imageId=", req.body.imageId);
        Favorite.add({uid:req.body.uid, imageId:req.body.imageId})
        .then(function(resData){
            console.log("result: ", resData);
            res.json(resData);
        });
        
        return;
    },
    /**
     * 获取所有
     */
    findByUserId: function(req, res, next) {
      console.log("request params: ", "uid=", req.query.uid);
      Favorite.findByUserId(req.query.uid)
        .then(function(resData){
          // let cs = [];
          // resData.forEach(i => {
          //   cs.push(Formats.Category(i));
          // });
          res.json(OK(resData));
        });

        return;
    }
}
